package leetcode_interview;

public class I0103 {

    public String replaceSpaces(String S, int length) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            if (S.charAt(i) != ' ')
                sb.append(S.charAt(i));
            else
                sb.append("%20");
        }
        return sb.toString();
    }

    public String replaceSpaces1(String S, int length) {
        return S.substring(0, length).replaceAll(" ", "%20");
    }
}
